package com.smartjobs.model;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.smartjobs.bean.CompanyBean;
import com.smartjobs.bean.JobseekerBean;
import com.smartjobs.util.DBManager;

public class LoginModel {

	public static boolean findJobseeker(JobseekerBean jobseeker) {

		String query = "SELECT * FROM jobseeker where emailId = '"
				+ jobseeker.getEmailID() + "' and passwd = '"
				+ jobseeker.getPassword() + "'";

		ResultSet result = DBManager.selectFromDB(query);

		try {
			if (result.next()) {

				jobseeker.setJobSeekerID(Integer.parseInt(result
						.getString("jobSeekerId")));
				jobseeker.setDob(result.getString("dob"));
				jobseeker.setMobileNumber(Integer.parseInt(result
						.getString("mobileNumber")));
				jobseeker.setName(result.getString("name"));
				return true;
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return false;

	}

	public static boolean findCompany(CompanyBean company) {

		String query = "SELECT * FROM companyprofile where emailId = '"
				+ company.getEmailID() + "' and companyPassword = '"
				+ company.getCompanyPassword() + "'";

		ResultSet result = DBManager.selectFromDB(query);

		try {
			if (result.next()) {

				company.setCompanyID(Integer.parseInt(result
						.getString("companyId")));
				company.setCompanyName(result.getString("companyName"));
				company.setPhoneNumber(result.getString("phoneNumber"));
				return true;
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return false;

	}

	public static int findTrainer(String name) {
		int trainerId = -1;

		String query = "SELECT * FROM trainer where trainerName = '" + name
				+ "'";

		ResultSet result = DBManager.selectFromDB(query);

		try {
			if (result.next()) {

				trainerId = result.getInt(1);
				return trainerId;
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return trainerId;

	}
}
